<template>
  <div>
    <el-page-header @back="goBack"></el-page-header>
    <div class="page-title">
      <div class="tit">超量账单</div>
      <div class="tip">
        超量账单每月1日生成，当存在两笔未支付的超量账单，API接口将无法再超量。超量账单仅支付企业服务余额支付。
        <!-- 超量账单每月1日生成，账单生成后{{delay_day}}天未支付超量费用的，API接口将无法超量。超量账单仅支付企业服务余额支付。 -->
      </div>
    </div>
    <!-- <el-card style="min-width: 1200px">
      <div class="tableSelectWrap">
        <el-form ref="balanceRecordForm" :model="dataForm" label-width="100px">
          <el-row>
            <el-col :span="7">
              <el-form-item label="选择时间" prop="date">
                <el-date-picker
                  v-model="dataForm.date"
                  style="width: 100%"
                  :clearable="false"
                  :default-time="['00:00:00', '23:59:59']"
                  type="datetimerange"
                  start-placeholder="开始时间"
                  end-placeholder="结束时间"
                  value-format="yyyy-MM-dd HH:mm:ss"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1">
              <el-form-item label="交易类型" prop="tradeType">
                <el-select
                  v-model="dataForm.tradeType"
                  clearable
                  style="width: 100%"
                  placeholder="请选择交易类型"
                >
                  <el-option
                    v-for="item of tradeType"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7" :offset="1" style="min-width: 170px">
              <el-button
                class="width120"
                @click="resetForm('balanceRecordForm')"
                >重置</el-button
              >
              <el-button type="primary" class="width120" @click="handleQuery"
                >查询</el-button
              >
            </el-col>
          </el-row>
        </el-form>
      </div>
    </el-card> -->
    <el-card style="margin-top: 15px; min-width: 1200px">
      <el-table
        :data="dataList"
        :height="fixedTableHeight"
        @selection-change="handleSelectionChange"
        ref="multipleTable"
      >
        <template slot="empty">
          <el-empty
            :image="require('@/assets/imgs/middleWork/k1.png')"
            :image-size="80"
            description="暂无相关数据"
          ></el-empty>
        </template>
        <el-table-column
          show-overflow-tooltip
          prop="gmtCreated"
          align="center"
          label="账单"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.billMonth ? scope.row.billMonth : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="orderNo"
          align="center"
          label="实际使用量/万次"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.fmtUsedCount ? scope.row.fmtUsedCount : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="info"
          align="center"
          label="超量/万次"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{ scope.row.fmtExcessCount ? scope.row.fmtExcessCount : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="cashAmt"
          sortable
          align="center"
          label="超量金额/元"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
            >
              {{
                scope.row.fmtExcessAmount ? scope.row.fmtExcessAmount : "0.00"
              }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="resetAmt"
          align="center"
          label="状态"
        >
          <template slot-scope="scope">
            <div
              style="
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
              :class="`${scope.row.status == 1 ? '' : 'pedding'} `"
            >
              {{ scope.row.statusName ? scope.row.statusName : "-" }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          prop="act"
          align="center"
          label="操作"
        >
          <template slot-scope="scope">
            <div>
              <el-button
                type="text"
                @click="handleToPay(scope.row)"
                v-if="scope.row.status != 1"
                >立即支付</el-button
              >
              <span v-else>-</span>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-pagination
      layout="prev, pager, next, sizes, jumper"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      :current-page="pageNum"
      :total="total"
      @current-change="pageCurrentChangeHandle"
      @size-change="pageSizeChangeHandle"
    >
    </el-pagination>
    <!-- <details-drawer :drawer.sync="drawer" :info="detailsInfo"></details-drawer> -->

    <!-- 余额不足弹窗 -->
    <el-dialog
      class="cardDialog"
      :visible.sync="chargeDia"
      :show-close="false"
      width="520px"
      top="30vh"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <div class="addTitle">
        <span>余额不足提醒</span>
      </div>
      <div class="tip">为不影响您的正常使用请务必合理设置</div>
      <el-form ref="form" :rules="rules" :model="form">
        <el-form-item
          label="最低金额"
          prop="fmtNoticeThreshold"
          label-position="top"
        >
          <el-select
            v-model="form.fmtNoticeThreshold"
            placeholder="请选择"
            class="width440"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="通知" class="notice">
          <el-checkbox v-model="form.emailType" class="width440">
            <el-form-item>
              邮件&nbsp;
              <el-input
                v-model="authInfo.email"
                placeholder="请输入邮箱"
                class="width380"
              ></el-input>
            </el-form-item>
          </el-checkbox>
          <el-checkbox v-model="form.phoneType" class="width440">
            <el-form-item>
              短信&nbsp;
              <el-input
                v-model="authInfo.mobilePhone"
                placeholder="请输入手机号"
                class="width380"
              ></el-input>
            </el-form-item>
          </el-checkbox>
          <!-- <el-radio-group v-model="form.noticeType" class="width440">
            <el-radio :label="1">邮件 {{ authInfo.email || "" }}</el-radio>
            <el-radio :label="0" :disabled="authInfo.mobilePhone == null"
              >短信 {{ authInfo.mobilePhone || "" }}</el-radio
            >
          </el-radio-group> -->
        </el-form-item>
      </el-form>
      <div class="tip1" v-if="authInfo.mobilePhone == null">
        系统管理员账号还未绑定手机号，无法选择短信提醒。
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cencelReset">取消</el-button>
        <el-button type="primary" @click="handleSubmit">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/mixin";

export default {
  name: "excessDetails",
  mixins: [mixin],
  data() {
    return {
      delay_day: 0,
      tradeType: [
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "鉴权划扣", value: "charge" },
        { id: 3, label: "升级补差", value: "charge2" },
        { id: 4, label: "用量超额费用", value: "withdrawal" },
        { id: 5, label: "充值", value: "order" },
      ],
      authInfo: {},
      options: [
        // {
        //   value: "10",
        //   label: "10元",
        // },
        // {
        //   value: "50",
        //   label: "50元",
        // },
        // {
        //   value: "100",
        //   label: "100元",
        // },
      ],
      cities: ["上海", "北京", "广州", "深圳"],
      form: {
        fmtNoticeThreshold: "",
        noticeType: "1",
      },
      ruleForm: {},
      checked1Name: "邮件",
      checked2Name: "短信",
      rules: {
        fmtNoticeThreshold: [
          { required: true, message: "金额不能为空", trigger: "change" },
          // {
          //   validator: this.checkAmount,
          //   trigger: "change",
          // },
        ],
        // noticeType: [
        //   { required: true, message: "不能为空", trigger: "change" },
        // ],
      },
      chargeDia: false,
      dataList: [],
      noticeS: false,
      multipleSelection: [],
      isPatch: false, //批量切换
      isTep: 1, //表格按钮切换
      activeKey: "1", //切换tab
      mixinViewModuleOptions: {
        getDataListURL: "/api/member/month/bill/searchByPage",
        createdIsNeed: true,
      },
      drawer: false,
      dataForm: {},
      detailsInfo: {},
      payChannel: [
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "微信", value: "wechat" },
        { id: 3, label: "支付宝", value: "ali" },
        { id: 4, label: "汇付", value: "ada" },
      ],
      statusList: [
        { id: 1, label: "所有", value: "" },
        { id: 2, label: "已完成", value: "success" },
        { id: 3, label: "处理中", value: "processing" },
        { id: 4, label: "提现失败", value: "fail" },
      ],
    };
  },
  created() {
    // this.getAccountDate();
  },
  methods: {
    getAccountDate() {
      this.$http
        .get("/api/manageConfig/getByKeySuffix?keySuffix=default_delay_day")
        .then((res) => {
          if (res.code === "0000") {
            console.log(res.data);
            this.delay_day = res.data;
            // this.$store.commit("changeMsgCount", res.data);
          }
        });
    },
    goBack() {
      this.$backTo("/qiye/systemUsage");
    },
    openDia1() {
      this.form.fmtNoticeThreshold = parseInt(this.authInfo.fmtNoticeThreshold);
      this.chargeDia = true;
    },
    openDia(val) {
      console.log(val);
      if (val) {
        this.chargeDia = true;
      } else {
        //发起关闭提醒权限请求
        this.$confirm("此操作将关闭余额不足提醒, 是否继续?", "提示", {
          customClass: "confirm",
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          showClose: false,
          closeOnClickModal: false,
          closeOnPressEscape: false,
          type: "warning",
          center: true,
        })
          .then(() => {
            let param = {
              id: this.authInfo.id,
              noticeType: -1,
              // fmtNoticeThreshold: this.authInfo.fmtNoticeThreshold,
            };
            console.log(param);
            this.$http
              .post("/api/merchant/memberauth/updateAuthAccount", param)
              .then((res) => {
                if (res.code === "0000") {
                  this.$message.success("关闭成功");
                  this.getAuthInfo();
                }
              });
          })
          .catch(() => {
            this.noticeS = true;
            // this.$message({
            //   type: "info",
            //   message: "已取消删除",
            // });
          });
      }
    },
    noticeSele(value) {
      console.log(value);
      // console.log(idx)
      console.log(this.form.checked1);
      if (value == 1) {
        //邮箱提醒
        if (this.form.checked2) {
          this.form.checked2 = !this.form.checked2;
        }
      } else {
        if (this.form.checked1) {
          this.form.checked1 = !this.form.checked1;
        }
      }
      // let checkedCount = value.length;
      // this.checkAll = checkedCount === this.cities.length;
      // this.isIndeterminate =
      //   checkedCount > 0 && checkedCount < this.cities.length;
    },
    cencelReset() {
      if (this.authInfo.noticeType == "-1") {
        this.noticeS = false;
      }

      this.chargeDia = false;
      this.$refs.form.resetFields(); //重置状态
    },
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          console.log(this.form);
          let param = {
            ...this.form,
            id: this.authInfo.id,
          };
          console.log(param);
          this.$http
            .post("/api/merchant/memberauth/updateAuthAccount", param)
            .then((res) => {
              if (res.code === "0000") {
                this.$message.success("设置成功");
                this.cencelReset();
                this.getAuthInfo();
              }
            });
        } else {
          return false;
        }
      });
    },
    handleTab() {
      this.pageSize = 10;
      this.resetForm("balanceRecordForm");
      if (this.activeKey == "1") {
        //获取鉴权信息
        this.getAuthInfo();
      }
      this.handleQuery();
    },
    handleClick() {
      this.isPatch = true;
      this.isTep = 2;
    },
    resetClick() {
      this.isPatch = false;
      this.multipleSelection = [];
      this.$refs.multipleTable.clearSelection();
      this.isTep = 1;
      //console.log(this.multipleSelection);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      //console.log(this.multipleSelection);
    },
    // handleClick(tab, event) {
    //   console.log(tab, event);
    // },
    handleToPay(row) {
      let param = {
        ids: [row.id],
      };
      this.$http
        .post("/api/member/month/bill/payExcess", param)
        .then((res) => {
          if (res.code == "0000") {
            this.$message.success("支付成功");
            this.getDataList();
          }
        })
        .catch(() => {
          // this.dataListLoading = false
        });
    },
    handleQuery() {
      this.pageNum = 1;
      if (this.dataForm.date && this.dataForm.date.length) {
        this.dataForm.gmtCreatedBegin = this.dataForm.date[0];
        this.dataForm.gmtCreatedEnd = this.dataForm.date[1];
      } else {
        this.dataForm.gmtCreatedBegin = "";
        this.dataForm.gmtCreatedEnd = "";
      }
      if (this.activeKey == "1") {
        this.getAuthList();
      } else {
        this.dataList = [];
        this.total = 0;
        this.noticeS = false;
        this.authInfo.noticeType = "-1";
      }
      // this.getDataList();
    },
    getAuthList() {
      this.$http
        .post("/api/merchant/memberauth/searchByPage", {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          params: {
            ...this.dataForm,
          },
          ...this.bodyForm,
        })
        .then((res) => {
          if (res.code == "0000") {
            console.log(res.data);
            this.dataList = res.data.list;
            this.total = res.data.total;
          }
        })
        .catch(() => {
          // this.dataListLoading = false
        });
    },
  },
};
</script>

<style scoped lang="scss">
.page-title {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  .tit {
    font-size: 24px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #1d1c1c;
    margin-right: 20px;
  }
  .tip {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
  }
}

.failed {
  color: #f42b2b;
}
.succeed {
  color: #07a555;
}
.pedding {
  color: #f69c1f;
}

.notice {
  :deep(.el-radio) {
    display: block;
    margin: 10px 0;
  }
}
.width440 {
  width: 440px;
}
.width380 {
  width: 380px;
}
.cardDialog {
  .addTitle {
    font-size: 20px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: bold;
    color: rgba(0, 0, 0, 0.85);
  }
  .tip {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.65);
    margin-top: 12px;
    margin-bottom: 30px;
    span {
      color: #03bfc6;
    }
  }
  .tip1 {
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #869daa;
    // line-height: 17px;
  }
  :deep(.el-form-item--small.el-form-item:nth-of-type(2)) {
    margin-bottom: 0;
  }
  :deep(.el-dialog) {
    border-radius: 16px;
  }
  :deep(.el-dialog__body) {
    padding: 10px 40px;
    padding-bottom: 60px;
  }
  :deep(.el-button--small) {
    width: 74px;
  }
  :deep(.el-input__inner) {
    padding-left: 12px;
  }
  :deep(.el-form-item__content) {
    position: relative;
  }
  .form-img {
    width: 22px;
    border-radius: 22px;
    position: absolute;
    top: 5px;
    left: 10px;
    z-index: 1;
  }
}
.setting {
  display: flex;
  justify-content: space-between;
  .tipBox {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
    display: flex;
    div {
      margin: 0 10px;
      cursor: pointer;
      &.color {
        color: #03bfc6;
      }
    }
  }
}

.pedding {
  color: #ee8917;
}
.switch {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
}
.ml {
  margin-left: 50px;
}
.search {
  position: absolute;
  right: 0;
  top: -164px;
}
</style>
